﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AccessGrant.GrantFrameworks;
using FAQFrameworks;
using FooFun.DataElements.Dtos;
using DTOFrameworks;

namespace FooFun.Web.Controls
{
    public class ForumsToAdmin : DataElementControl
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            PermissionQuery query = PermissionQuery.Create();
            RoleSetQuery roleSetQuery = RoleSetQuery.Create();

            IEnumItem role = query.GetAccountByName("版主");

            UserManager userManager = new UserManager();
            IEnumItem user
                = userManager.GetElement(FAQContext.Current.User.AccountId)
                as IEnumItem;

            if (user != null)
            {
                IDataElement forumList
                    = roleSetQuery.ListForumOfUserInRole(user,
                    role);

                this.DataElement = forumList;
            }
            else
            {
                this.DataElement = new EmptyDataElement();
            }
        }
    }
}
